home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / moni / systemviewer.lha / GetDOSAssigns.c < prev    next >
C/C++ Source or Header  |  1999-12-06  |  5KB  |  188 lines

  1. /***********************************************************************************/
  2. /*                                                                                 */
  3. /* This is meant to be just a didactic example for who want to know to get device, */
  4. /* volume or assign names, but it can be used for any thing you want.              */
  5. /*                                                                                 */
  6. /* No limitations. Really!                                                         */
  7. /*                                                                                 */
  8. /* Author: Michele Locati                                                          */
  9. /* EMail : mlocati@rocketmail.com                                                  */
  10. /* Date  : 17/10/97 (friday!)                                                      */
  11. /*                                                                                 */
  12. /***********************************************************************************/
  13. /***********************************************************************************/
  14. /*                                                                                 */
  15. /* Compiled with Dice v3.20 (1.6.96) for Amigas with 2.0+                          */
  16. /*                                                                                 */
  17. /***********************************************************************************/
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21.  
  22. #include <clib/dos_protos.h>
  23.  
  24. #include <dos/dosextens.h>
  25.  
  26. BOOL GetDosList( void );
  27.  
  28. void FreeDosList( void );
  29.  
  30. STRPTR BCPL2STRPTR( BSTR s );
  31.  
  32. typedef struct {
  33.  
  34.    STRPTR Name;
  35.    STRPTR Drive;
  36.  
  37. } Volume;
  38.  
  39. typedef struct {
  40.  
  41.    STRPTR Name;
  42.    STRPTR Path;
  43.  
  44. } Assign;
  45.  
  46. Volume *Volumes;
  47. Assign *Assigns;
  48. STRPTR *Devices;
  49.  
  50. int  NumVolumes, NumAssigns, NumDevices;
  51.  
  52. char strtmp[256];
  53.  
  54. /* wbmain() is called when starting from Workbench*/
  55.  
  56. int wbmain( void )
  57. {
  58.    return( main() );
  59. }
  60.  
  61. int main( void )
  62. {
  63.    int i;
  64.     
  65.    GetDosList();
  66.  
  67.    printf( "Assigns: %d\n", NumAssigns );
  68.  
  69.    for (i = 0; i < NumAssigns; i++)
  70.       printf( "\t%s:\t%s\n", Assigns[i].Name, Assigns[i].Path );
  71.     
  72.    printf( "\nVolumes: %d\n", NumVolumes );
  73.    for (i = 0; i < NumVolumes; i++)
  74.       printf( "\t%s:\t%s\n", Volumes[i].Drive, Volumes[i].Name );
  75.  
  76.    printf( "\nDevices: %d\n", NumDevices );
  77.    for (i = 0; i < NumDevices; i++)
  78.       printf( "\t%s\n", Devices[i] );
  79.  
  80.    FreeDosList();
  81.  
  82.    return( 0 );
  83. }
  84.  
  85. BOOL GetDosList(void)
  86. {
  87.     struct DosList *dl;
  88.     int i;
  89.  
  90.     
  91.     printf("Getting assigns...\n");
  92.     NumAssigns=0;
  93.     dl=LockDosList(LDF_ASSIGNS | LDF_READ);
  94.     while (dl=NextDosEntry(dl, LDF_ASSIGNS))
  95.         NumAssigns++;
  96.     UnLockDosList(LDF_ASSIGNS | LDF_READ);
  97.     Assigns=(Assign *)malloc(NumAssigns * sizeof(Assign));
  98.     i=0;
  99.     dl=LockDosList(LDF_ASSIGNS | LDF_READ);
  100.     while (dl=NextDosEntry(dl, LDF_ASSIGNS))
  101.     {
  102.         Assigns[i].Name=BCPL2STRPTR(dl->dol_Name);
  103.         NameFromLock(dl->dol_Lock, strtmp, 255);
  104.         Assigns[i].Path=strdup(strtmp);
  105.         i++;
  106.     }
  107.     UnLockDosList(LDF_ASSIGNS | LDF_READ);
  108.  
  109.  
  110.     printf("Getting volumes...\n");
  111.     NumVolumes=0;
  112.     dl=LockDosList(LDF_VOLUMES | LDF_READ);
  113.     while (dl=NextDosEntry(dl, LDF_VOLUMES))
  114.         NumVolumes++;
  115.     UnLockDosList(LDF_VOLUMES | LDF_READ);
  116.     Volumes=(Volume *)malloc(NumVolumes * sizeof(Volume));
  117.     i=0;
  118.     dl=LockDosList(LDF_VOLUMES | LDF_READ);
  119.     while (dl=NextDosEntry(dl, LDF_VOLUMES))
  120.     {
  121.         Volumes[i].Drive=strdup(((struct Task *)dl->dol_Task->mp_SigTask)->tc_Node.ln_Name);
  122.         Volumes[i++].Name=BCPL2STRPTR(dl->dol_Name);
  123.     }
  124.     UnLockDosList(LDF_VOLUMES | LDF_READ);
  125.  
  126.  
  127.     printf("Getting devices...\n");
  128.     NumDevices=0;
  129.     dl=LockDosList(LDF_DEVICES | LDF_READ);
  130.     while (dl=NextDosEntry(dl, LDF_DEVICES))
  131.         NumDevices++;
  132.     UnLockDosList(LDF_DEVICES | LDF_READ);
  133.     Devices=(STRPTR *)malloc(NumDevices * sizeof(STRPTR));
  134.     i=0;
  135.     dl=LockDosList(LDF_DEVICES | LDF_READ);
  136.     while (dl=NextDosEntry(dl, LDF_DEVICES))
  137.         Devices[i++]=BCPL2STRPTR(dl->dol_Name);
  138.     UnLockDosList(LDF_DEVICES | LDF_READ);
  139. }
  140.  
  141. STRPTR BCPL2STRPTR(BSTR s)
  142. {
  143.     STRPTR ris;
  144.     STRPTR eq;
  145.     
  146.     if (!s)
  147.         return(NULL);
  148.     eq=(STRPTR)BADDR(s);
  149.     if (!eq[0])
  150.         return(NULL);
  151.     ris=(STRPTR)malloc(eq[0] + 1);
  152.     memcpy(ris, eq + 1, eq[0]);
  153.     ris[eq[0]]=0;
  154.     return(ris);
  155. }
  156.  
  157. void FreeDosList(void)
  158. {
  159.     int i;
  160.  
  161.     
  162.     printf("Freeing assigns...");
  163.     for (i=0; i<NumAssigns; i++)
  164.     {
  165.         free(Assigns[i].Name);
  166.         free(Assigns[i].Path);
  167.     }
  168.     free(Assigns);
  169.     NumAssigns=0;
  170.  
  171.  
  172.     printf("\nFreeing volumes...\n");
  173.     for (i=0; i<NumVolumes; i++)
  174.     {
  175.         free(Volumes[i].Drive);
  176.         free(Volumes[i].Name);
  177.     }
  178.     free(Volumes);
  179.     NumVolumes=0;
  180.  
  181.     
  182.     printf("Freeing devices...\n");
  183.     for (i=0; i<NumDevices; i++)
  184.         free(Devices[i]);
  185.     free(Devices);
  186.     NumDevices=0;
  187. }
  188.